package com.sw.rpc.service.zk;

import java.io.Serializable;
import java.time.Instant;
import java.util.Comparator;

/**
 * 数据节点信息
 * @author wodezuiaishinageren
 */
public class ZkNodeData implements Serializable, Comparator {

    private static final long serialVersionUID = -718160458266606600L;
    private String ip;
    private int port;
    /**
     * 最后响应时间
     */
    private Instant lastResponseTime;
    /**
     * 服务处理时常
     */
    private long handlerTime;

    public Instant getLastResponseTime() {
        return lastResponseTime;
    }

    public void setLastResponseTime(Instant lastResponseTime) {
        this.lastResponseTime = lastResponseTime;
    }

    public long getHandlerTime() {
        return handlerTime;
    }

    public void setHandlerTime(long handlerTime) {
        this.handlerTime = handlerTime;
    }

    public ZkNodeData(String ip, int port) {
        this.ip = ip;
        this.port = port;
    }

    public ZkNodeData() {
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    @Override
    public String toString() {
        return "ZkNodeData{" +
                "ip='" + ip + '\'' +
                ", port=" + port +
                '}';
    }


    @Override
    public int compare(Object o1, Object o2) {
        ZkNodeData z1= (ZkNodeData) o1;
        ZkNodeData z2=(ZkNodeData)o2;
        return (int)((ZkNodeData) o1).getHandlerTime() - (int)((ZkNodeData) o2).getHandlerTime();
    }
}
